local S = minetest.get_translator("defense_healing")

local function heal(obj, amount)
	obj:set_hp(obj:get_hp() + amount)
	minetest.sound_play("defense_healing_drink",
		{
			object = obj,
			max_hear_distance = 4,
		})
end


local juice_helpstr = minetest.colorize(
	"#90FFFF",
	S("Tastes revolting. Best used to heal others"))
minetest.register_craftitem("defense_healing:juice",
	{
		description = S("Chugging Juice Jug\n@1", juice_helpstr),
		inventory_image = "defense_healing_juice.png",
		stack_max = 1,
		on_use = function(itemstack, user)
			if user
			then
				heal(user, 1)
			end
		end,
		on_drop = function(itemstack)
			return itemstack --undroppable to prevent nasty accidents
		end,
		on_place = function(itemstack, user, pointed_thing)
			--heal other players
			
			--ensure that pointed_thing is a player
			if pointed_thing.type ~= "object" or
				not pointed_thing.ref:is_player()
			then
				return
			end
			heal(user, 4)
		end,
	})
minetest.register_alias("healing_juice", "defense_healing:juice")

minetest.register_craftitem("defense_healing:stonecake",
	{
		description = S("Stone Cake"),
		inventory_image = "defense_healing_cake.png",
		stack_max = 64,
		on_use = minetest.item_eat(5)
	})
minetest.register_alias("healing_cake", "defense_healing:stonecake")

minetest.register_craft(
	{
		type = "cooking",
		output = minetest.registered_aliases["healing_cake"],
		recipe = minetest.registered_aliases["cobble"],
		cooktime = 2,
	})

give_initial_stuff.add("healing_juice", 3)
give_initial_stuff.add("healing_cake 8", 1)
